import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

import '../../../../resource/language/generated/l10n.dart';
import '../../../m_chatroom.dart';
import '../../hall/room_main/room_life_cycle_mixin.dart';
import '../../hall/room_main/room_page_mixin.dart';
import '../../interface/room_page_model.dart';
import '../../template/music/page/room_music_page.dart';
import '../privilege/privilege_desc_widget.dart';
import '../ride_topic_widget.dart';

class DoufengRoomMainPage extends StatefulWidget {
  DoufengRoomMainPage({super.key});

  @override
  State<DoufengRoomMainPage> createState() => _DoufengRoomMainPageState();
}

class _DoufengRoomMainPageState extends State<DoufengRoomMainPage>
    with
        WidgetsBindingObserver,
        SingleTickerProviderStateMixin,
        RoomLifecycleMixin,
        RoomPageMixin {
  late VoidCallback barRightAction;

  @override
  Widget get roomHeader => Container(
        height: 30,
        width: 200,
        color: Colors.red,
      );

  Widget get privilegeDesc => const PrivilegeDescWidget();

  // bool get isBoss =>
  //     model.roomModel.meWithSlot?.micType == MicTypeEnum.CAR_OWNER_MIC;

  bool get isBoss => true;

  Widget get topics => Container(
        height: 100,
        alignment: Alignment.center,
        child: isBoss ? const SizedBox() : const RideTopicWidget(),
      );

  @override
  Widget get topEntry => const SizedBox();

  @override
  Widget get clubOnlineList => const SizedBox();

  @override
  List<Widget> get columnWidgets => [
        roomHeader,
        topics,
        roomMics,
        // DoufengTimeCheckWidget(),
        const SizedBox(
          height: 20,
        ),
        operationOrPrivilegeDesc,
        msgArea,
        musicBar,
        roomBottom,
      ];

  @override
  List<Widget> get stackWidgets => [
        // roomBg,
        Text('roomBg'),
        roomColumn,
        // carArea,
        giftAnimation,
        joinAnimation,
      ];

  @override
  Widget build(BuildContext context) {
    return Consumer<RoomPageModel>(builder: (context, model, child) {
      return Scaffold(
        //键盘弹出不积压上部内容
        key: model.mainKey,
        resizeToAvoidBottomInset: false,
        body: body,
      );
    });
  }

  Widget get operationOrPrivilegeDesc {
    // if (!(model.channel?.isDouFeng ?? false)) return const SizedBox();
    // if (model.roomModel.ridePush?.privilege.operation ==
    //     PrivilegeOperation.USE) {
    return const PrivilegeDescWidget();
    // } else {
    //   return operateItems;
    // }
  }

  Widget get operateItems {
    // if (!(model.channel?.isDouFeng ?? false)) return const SizedBox();

    return Container(
      width: double.infinity,
      alignment: Alignment.topCenter,
      child: Row(
        mainAxisSize: MainAxisSize.min,
        children: [
          CupertinoButton(
            onPressed: () {
              model.openPrivilegePage(context);
            },
            minSize: 0,
            padding: EdgeInsets.zero,
            child: Column(
              mainAxisSize: MainAxisSize.min,
              children: [
                Image.asset(
                  "assets/images/ic_doufeng_tequan.png",
                  width: 42,
                  height: 42,
                  fit: BoxFit.contain,
                ),
                const SizedBox(
                  height: 4,
                ),
                Text(
                  T.current.privilege,
                  style: const TextStyle(
                    color: Colors.white,
                    fontSize: 11,
                    fontWeight: FontWeight.w500,
                  ),
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }

  @override
  Widget get roomBottom => Padding(
        padding: const EdgeInsets.only(bottom: 10, left: 20, right: 20),
        child: Row(
          children: [
            msgIcon,
            giftIcon,
            imIcon,
            toolsIcon,
          ],
        ),
      );

  void showMusic(BuildContext context) async {
    await RoomMusicPage.show();
    if (mounted) {
      model.roomModel.notifyListeners();
    }
  }
}
